package com.hwadee.teachingprocessmanagementsystem.controller.base;

import com.hwadee.teachingprocessmanagementsystem.entity.Course;
import com.hwadee.teachingprocessmanagementsystem.entity.Major;
import com.hwadee.teachingprocessmanagementsystem.service.base.MajorService;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * (Major)表控制层
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@RestController
@RequestMapping("major")
public class MajorController {
    /**
     * 服务对象
     */
    @Resource
    private MajorService majorService;


    @RequestMapping
    public ResponseEntity<org.springframework.core.io.Resource> courseStandards(@RequestParam("majorId") String majorId) {
        // 根据课程编号查询课程标准
        Major major = this.majorService.queryById(Integer.parseInt(majorId));
        try {
            // 获取pdf文件路径
            Path pdfPath = Paths.get("static/talent-plan/" + majorId + "/" + major.getTeachingPlan());
            System.out.println(pdfPath.toString());
            org.springframework.core.io.Resource resource = new ClassPathResource(pdfPath.toString());
            HttpHeaders headers = new HttpHeaders();
            headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=talent-plan.pdf");
            return new ResponseEntity<>(resource, headers, HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    }

}

